package com.yunxi.controller.sat;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sat.pojo.EvaluateVO;
import com.yunxi.sat.service.EvaluateDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 满意度表 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-09-26
 */
@RestController
@RequestMapping("/admin/evaluate")
@Api(tags = "sat:evaluate", description = "满意度表接口")
public class EvaluateController {
    private static final Logger logger = LoggerFactory.getLogger(EvaluateController.class);

    @Autowired
    EvaluateDubboService evaluateDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询满意度表分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult page(EvaluateVO evaluateVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(evaluateDubboService.findPageByVO(evaluateVO, pageNum, pageSize,loginInfo));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询满意度表列表")
    public ApiResult list(EvaluateVO evaluateVO) throws Exception {
        return ResponseUtil.ok(evaluateDubboService.listByVo(evaluateVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个满意度表")
    @ApiImplicitParam(paramType="query", name = "evalId", value = "主键ID", required = true, dataType = "String")
    public ApiResult load(String evalId) throws Exception {
        return ResponseUtil.ok(evaluateDubboService.getById(evalId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存满意度表信息")
    public ApiResult save(@RequestBody EvaluateVO evaluateVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        evaluateDubboService.saveOrUpdate(evaluateVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除满意度表")
    public ApiResult del(@RequestBody List<EvaluateVO> evaluateVOList) throws Exception {
        evaluateDubboService.removeByListVo(evaluateVOList);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/evaluateCount")
    @ApiOperation(value = "满意度统计")
    public ApiResult evaluateCount(@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(evaluateDubboService.evaluateCount(loginInfo));
    }

}
